package cn.m3a1.creditsystem.service;

import cn.m3a1.creditsystem.bean.*;
import cn.m3a1.creditsystem.dao.StudentScheduleMapper;
import cn.m3a1.creditsystem.dao.StudentScheduleModelMapper;
import cn.m3a1.creditsystem.util.MyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author wyj
 * @date 2020/2/12
 * @time 下午12:59
 */
@Service
@Transactional
public class StudentScheduleService {
    @Autowired
    StudentScheduleMapper studentScheduleMapper;
    @Autowired
    StudentScheduleModelMapper studentScheduleModelMapper;
//    course_name课程名称
//    student_id 学号
//    student_name 姓名
//    teacher_id 教师工号
//    teacher_name 教师名字
//    credit  学分
//    course_nature  课程性质
//    time		上课时间
//    class_locations 上课地点
//    examination_time 考试时间
//    examination_localtions 考试地点
//    grade_year 年级
//    college 学院
//    professional_title 专业名称
//    class_name 班级名称

    public Boolean inserts(List<List<String>> list) {

        for (int i = 2; i < list.size(); i++) {
            List<String> lo = list.get(i);
            StudentSchedule studentSchedule =new StudentSchedule();
            studentSchedule.setCourseName(lo.get(1));
            studentSchedule.setStudentId(lo.get(2));
            studentSchedule.setStudentName(lo.get(3));
            studentSchedule.setTeacherId(lo.get(5));
            studentSchedule.setTeacherName(lo.get(6));
            if (lo.get(7)!=""){
                studentSchedule.setCredit(Integer.parseInt(lo.get(7)));
            }
            studentSchedule.setCourseNature(lo.get(8));
            studentSchedule.setTime(lo.get(9));
            studentSchedule.setClassLocations(lo.get(10));
            studentSchedule.setExaminationTime(lo.get(12));
            studentSchedule.setExaminationLocaltions(lo.get(13));
            studentSchedule.setGradeYear(lo.get(14));
            studentSchedule.setCollege(lo.get(15));
            studentSchedule.setProfessionalTitle(lo.get(16));
            studentSchedule.setClassName(lo.get(17));
            studentScheduleMapper.insert(studentSchedule);
        }

        return true;
    }
    public  List<StudentSchedule> selectAll(){
        StudentScheduleExample studentScheduleExample = new StudentScheduleExample();
        List<StudentSchedule> studentSchedules = studentScheduleMapper.selectByExample(studentScheduleExample);
        return studentSchedules;

    }
    public Boolean  inserts_model(List<StudentSchedule> list){
        for (StudentSchedule stu:list
                ) {
            //SchoolScheduleModel schoolScheduleModel=new SchoolScheduleModel();
            MyUtil myUtil =new MyUtil();
            if (myUtil.getStudentScheduleModel(stu)==null){
                continue;
            }
            List<StudentScheduleModel> schoolScheduleModels = myUtil.getStudentScheduleModel(stu);

            for (StudentScheduleModel studentScheduleModel:
                    schoolScheduleModels) {
                studentScheduleModelMapper.insert(studentScheduleModel);
            }

            //System.out.println(sche.getId());
        }
        return true;
    }

    public List<StudentSchedule> selectstu(StudentSchedule studentSchedule) {
        StudentScheduleExample scheduleExample = new StudentScheduleExample();
        StudentScheduleExample.Criteria criteria = scheduleExample.createCriteria();
        if (studentSchedule.getStudentId()!=null){
            criteria.andStudentIdLike("%"+studentSchedule.getStudentId().trim()+"%");
        }
        if (studentSchedule.getCourseName()!=null){
            criteria.andCourseNameLike("%"+studentSchedule.getCourseName().trim()+"%");
        }
        if (studentSchedule.getTeacherName()!=null){
            System.out.println(studentSchedule.getTeacherName());
            criteria.andTeacherNameLike("%"+studentSchedule.getTeacherName().trim()+"%");
        }
        if (studentSchedule.getStudentName()!=null){
            criteria.andStudentNameLike("%"+studentSchedule.getStudentName().trim()+"%");
        }
        if (studentSchedule.getClassName()!=null){
            criteria.andClassNameLike("%"+studentSchedule.getClassName().trim()+"%");
        }
        List<StudentSchedule> studentSchedules = studentScheduleMapper.selectByExample(scheduleExample);
        return  studentSchedules;
    }
}
